/*
 * @Author: your name
 * @Date: 1970-01-01 08:00:00
 * @LastEditTime: 2020-08-05 22:47:48
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /Linux系统编程/msg_com_blood.c
 */ 
#include <sys/types.h>
#include <sys/msg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// TODO: ???????????fork???????????
struct msgbuf
{
    long type;
    char voltage[124];
    char ID[4];
};

int main()
{
    int msgid;
    struct msgbuf sendbuf;
    struct msgbuf recvbuf;
    msgid = msgget(ftok("./a.c", "a"), IPC_CREAT | 0777);

    memset(recvbuf.voltage,0,124);


    // write message queue 
    while (1)
    {
        memset(recvbuf.voltage, 0, 124);
        // start read message from message queue
        int readret = msgrcv(msgid, (void *)&recvbuf, 124, 100, 0);
        printf("recv len = %d, recv: %s", readret, recvbuf.voltage);
        
    }

// error
    msgctl(msgid, IPC_RMID, NULL);



}